<template>
	<div class="layout-padding">
		<div class="layout-padding-auto layout-padding-view">
			<el-row v-show="showSearch">
				<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
					<el-form-item label="请假类型" prop="leaveType">
						<el-select v-model="state.queryForm.leaveType" placeholder="请选择请假类型">
							<el-option :label="item.label" :value="item.value" v-for="(item, index) in leave_type" :key="index"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="开始日期" prop="startDate">
						<el-date-picker type="date" placeholder="请输入开始日期" v-model="state.queryForm.startDate"></el-date-picker>
					</el-form-item>
					<el-form-item label="结束日期" prop="endDate">
						<el-date-picker type="date" placeholder="请输入结束日期" v-model="state.queryForm.endDate"></el-date-picker>
					</el-form-item>
					<el-form-item>
						<el-button icon="search" type="primary" @click="getDataList"> 查询</el-button>
						<el-button icon="Refresh" @click="resetQuery">重置</el-button>
					</el-form-item>
				</el-form>
			</el-row>
			<el-table
				:data="state.dataList"
				v-loading="state.loading"
				border
				:cell-style="tableStyle.cellStyle"
				:header-cell-style="tableStyle.headerCellStyle"
				@sort-change="sortChangeHandle"
			>
				<el-table-column type="index" label="#" width="40" />
				<el-table-column label="标题" prop="processName" show-overflow-tooltip />
				<el-table-column prop="createTime" label="申请日期" show-overflow-tooltip />
				<el-table-column prop="instanceState" label="流程状态" show-overflow-tooltip>
					<template #default="scope">
						<dict-tag :options="instance_status" :value="scope.row.instanceState"></dict-tag>
					</template>
				</el-table-column>
			</el-table>
			<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
		</div>

		<!-- 编辑、新增  -->
		<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
	</div>
</template>

<script setup lang="ts" name="systemApproval">
import { BasicTableProps, useTable } from '@/hooks/table';
import { getMyLaunch } from '@/api/oa/approval';
import { useMessage, useMessageBox } from '@/hooks/message';
import { useDict } from '@/hooks/dict';

// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// 定义查询字典

const { leave_type, instance_status } = useDict('leave_type', 'instance_status');
// 定义变量内容
const formDialogRef = ref();
// 搜索变量
const queryRef = ref();
const showSearch = ref(true);
// 多选变量
const selectObjs = ref([]) as any;

const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: getMyLaunch,
});

//  table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile, tableStyle } = useTable(state);

// 清空搜索条件
const resetQuery = () => {
	// 清空搜索条件
	queryRef.value?.resetFields();
	// 清空多选
	selectObjs.value = [];
	getDataList();
};
</script>
